package com.wuliang.generate.bean.entities.datasource;

import com.google.gson.annotations.Expose;
import com.wuliang.generate.common.core.basic.BasicEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.context.annotation.Lazy;

import javax.persistence.Cacheable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import java.util.Set;

/**
 * @author 邬魉
 */
@Data
@Lazy
@Entity
@Builder
@Cacheable
@ApiModel("数据库")
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@Table(name = "t_datasource_schema", schema = "wuliang_generate_datasource")
public class DatasourceSchema extends BasicEntity {

    @Expose
    @Column(name = "schema_name", columnDefinition = "varchar(255) default null comment '数据库名'")
    @ApiModelProperty(name = "schemaName", value = "数据库名", dataType = "string")
    private String schemaName;

    @Expose
    @Column(name = "schema_charter", columnDefinition = "varchar(255) default 'utf8' comment '数据库编码'")
    @ApiModelProperty(name = "schemaCharter", value = "数据库编码", dataType = "string")
    private String schemaCharter;

    @Expose
    @Column(name = "schema_collate", columnDefinition = "varchar(255) default 'utf8_bin' comment '编码引擎'")
    @ApiModelProperty(name = "schemaCollate", value = "编码引擎", dataType = "string")
    private String schemaCollate;

    @Expose
    @OneToMany(fetch = FetchType.EAGER)
    @JoinColumn(name = "schema_id", referencedColumnName = "id")
    private Set<DatasourceTable> tables;

}
